<template>
    <el-container class="home-container">
        <!--    导航-->
        <el-header>
            <div>
        <span style="margin-left:20px;">
          <img
                  src="../assets/ilogo.png"
                  width="250px;"
                  style="margin-left:-10px;"
                  height="100%;"
                  alt
                  srcset
          />
        </span>
            </div>
            <el-dropdown>
                <div class="block">
                    <el-avatar  :size="50" :src="this.userInfo.avatar" style="cursor: pointer;"></el-avatar>
                </div>
                <el-dropdown-menu slot="dropdown" trigger="click">
                    <el-dropdown-item>
                        <span type="danger"  @click="toWelcome"><span class="el-icon-house"></span> &nbsp;系统首页</span>
                    </el-dropdown-item>


                    <el-dropdown-item>

                        <span type="danger" @click="getContact"><span class="el-icon-ship"></span> &nbsp;交流讨论</span>

                    </el-dropdown-item>

                    <el-dropdown-item>

                        <span type="danger" @click="logout"><span class="el-icon-switch-button"></span> &nbsp;退出登入</span>

                    </el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
        </el-header>
        <!--主体-->
        <el-container style="height: 500px;">
            <!--菜单-->
            <el-aside :width="isOpen==true?'64px':'200px'">
                <div class="toggle-btn" @click="toggleMenu">|||</div>
                <el-menu
                        class="el-menu-vertical-demo"
                        :collapse="isOpen"
                        :router="true"
                        :default-active="activePath"
                        background-color="#001529"
                        :collapse-transition="false"
                        text-color="rgba(255,255,255,0.7)"
                        unique-opened
                >
                    <MenuTree  :menuList="menuList"></MenuTree>
                </el-menu>
            </el-aside>

            <!--右边主体-->
            <el-main v-loading="loading">

                <router-view></router-view>

            </el-main>
        </el-container>
    </el-container>
</template>

<script>
    import MenuTree from "./MenuTree.vue"; //引进菜单模板

    export default {
        data() {
            return {
                loading: true,
                activePath: "", //激活的路径
                isOpen: false,
                menuList: [
                    {
                        "id": 1,
                        "parentId": 0,
                        "menuName": "系统管理",
                        "url": "",
                        "icon": "el-icon-setting",
                        "orderNum": 1,
                        "open": 0,
                        "disabled": false,
                        "perms": null,
                        "type": 0,
                        "children": [
                            {
                                "id": 253,
                                "parentId": 1,
                                "menuName": "系统首页",
                                "url": "/welcome",
                                "icon": "el-icon-star-off",
                                "orderNum": 1,
                                "open": 0,
                                "disabled": false,
                                "perms": "welcome:view",
                                "type": 0,
                                "children": []
                            },
                            {
                                "id": 226,
                                "parentId": 1,
                                "menuName": "用户管理",
                                "url": "/users",
                                "icon": "el-icon-user",
                                "orderNum": 2,
                                "open": 0,
                                "disabled": false,
                                "perms": "users",
                                "type": 0,
                                "children": []
                            },
                            {
                                "id": 321,
                                "parentId": 1,
                                "menuName": "附件管理",
                                "url": "/attachments",
                                "icon": "el-icon-picture-outline",
                                "orderNum": 2,
                                "open": 1,
                                "disabled": false,
                                "perms": "",
                                "type": 0,
                                "children": []
                            },
                            {
                                "id": 4,
                                "parentId": 1,
                                "menuName": "菜单权限",
                                "url": "/menus",
                                "icon": "el-icon-help",
                                "orderNum": 3,
                                "open": 0,
                                "disabled": false,
                                "perms": null,
                                "type": 0,
                                "children": []
                            },
                            {
                                "id": 235,
                                "parentId": 1,
                                "menuName": "角色管理",
                                "url": "/roles",
                                "icon": "el-icon-postcard",
                                "orderNum": 3,
                                "open": 0,
                                "disabled": false,
                                "perms": "",
                                "type": 0,
                                "children": []
                            },
                            {
                                "id": 261,
                                "parentId": 1,
                                "menuName": "部门管理",
                                "url": "/departments",
                                "icon": "el-icon-s-home",
                                "orderNum": 3,
                                "open": 0,
                                "disabled": false,
                                "perms": "",
                                "type": 0,
                                "children": []
                            },
                            {
                                "id": 319,
                                "parentId": 1,
                                "menuName": "公告管理",
                                "url": "/notices",
                                "icon": "el-icon-s-flag",
                                "orderNum": 4,
                                "open": 0,
                                "disabled": true,
                                "perms": "",
                                "type": 0,
                                "children": []
                            }
                        ]
                    },
                    {
                        "id": 312,
                        "parentId": 0,
                        "menuName": "业务管理",
                        "url": null,
                        "icon": "el-icon-s-goods",
                        "orderNum": 2,
                        "open": 1,
                        "disabled": false,
                        "perms": null,
                        "type": 0,
                        "children": [
                            {
                                "id": 229,
                                "parentId": 312,
                                "menuName": "物资管理",
                                "url": "",
                                "icon": "el-icon-date",
                                "orderNum": 1,
                                "open": 1,
                                "disabled": false,
                                "perms": "el-icon-date",
                                "type": 0,
                                "children": [
                                    {
                                        "id": 230,
                                        "parentId": 229,
                                        "menuName": "物资入库",
                                        "url": "/inStocks",
                                        "icon": "el-icon-date",
                                        "orderNum": 1,
                                        "open": 0,
                                        "disabled": false,
                                        "perms": "el-icon-date",
                                        "type": 0,
                                        "children": []
                                    },
                                    {
                                        "id": 267,
                                        "parentId": 229,
                                        "menuName": "物资资料",
                                        "url": "/products",
                                        "icon": "el-icon-goods",
                                        "orderNum": 2,
                                        "open": 0,
                                        "disabled": false,
                                        "perms": "",
                                        "type": 0,
                                        "children": []
                                    },
                                    {
                                        "id": 268,
                                        "parentId": 229,
                                        "menuName": "物资类别",
                                        "url": "/productCategorys",
                                        "icon": "el-icon-star-off",
                                        "orderNum": 2,
                                        "open": 0,
                                        "disabled": false,
                                        "perms": "",
                                        "type": 0,
                                        "children": []
                                    },
                                    {
                                        "id": 270,
                                        "parentId": 229,
                                        "menuName": "物资发放",
                                        "url": "/outStocks",
                                        "icon": "el-icon-goods",
                                        "orderNum": 5,
                                        "open": 1,
                                        "disabled": false,
                                        "perms": "",
                                        "type": 0,
                                        "children": []
                                    },
                                    {
                                        "id": 316,
                                        "parentId": 229,
                                        "menuName": "物资库存",
                                        "url": "/stocks",
                                        "icon": "el-icon-tickets",
                                        "orderNum": 5,
                                        "open": 0,
                                        "disabled": false,
                                        "perms": "",
                                        "type": 0,
                                        "children": []
                                    }
                                ]
                            },
                            {
                                "id": 311,
                                "parentId": 312,
                                "menuName": "物资流向",
                                "url": null,
                                "icon": "el-icon-edit",
                                "orderNum": 3,
                                "open": 0,
                                "disabled": false,
                                "perms": null,
                                "type": 0,
                                "children": [
                                    {
                                        "id": 310,
                                        "parentId": 311,
                                        "menuName": "物资去处",
                                        "url": "/consumers",
                                        "icon": "el-icon-edit",
                                        "orderNum": 1,
                                        "open": 0,
                                        "disabled": false,
                                        "perms": "",
                                        "type": 0,
                                        "children": []
                                    },
                                    {
                                        "id": 269,
                                        "parentId": 311,
                                        "menuName": "物资来源",
                                        "url": "/suppliers",
                                        "icon": "el-icon-coordinate",
                                        "orderNum": 5,
                                        "open": 0,
                                        "disabled": false,
                                        "perms": "",
                                        "type": 0,
                                        "children": []
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "id": 303,
                        "parentId": 0,
                        "menuName": "健康报备",
                        "url": "",
                        "icon": "el-icon-platform-eleme",
                        "orderNum": 3,
                        "open": 0,
                        "disabled": false,
                        "perms": "",
                        "type": 0,
                        "children": [
                            {
                                "id": 273,
                                "parentId": 303,
                                "menuName": "全国疫情",
                                "url": "/map",
                                "icon": "el-icon-s-opportunity",
                                "orderNum": 1,
                                "open": 1,
                                "disabled": false,
                                "perms": "map:view",
                                "type": 0,
                                "children": []
                            },
                            {
                                "id": 304,
                                "parentId": 303,
                                "menuName": "健康打卡",
                                "url": "/health",
                                "icon": "el-icon-s-cooperation",
                                "orderNum": 1,
                                "open": 0,
                                "disabled": false,
                                "perms": "",
                                "type": 0,
                                "children": []
                            },
                            {
                                "id": 305,
                                "parentId": 303,
                                "menuName": "查看情况",
                                "url": null,
                                "icon": "el-icon-c-scale-to-original",
                                "orderNum": 2,
                                "open": 1,
                                "disabled": true,
                                "perms": null,
                                "type": 0,
                                "children": []
                            },
                            {
                                "id": 272,
                                "parentId": 303,
                                "menuName": "疫情辟谣",
                                "url": "/rumors",
                                "icon": "el-icon-help",
                                "orderNum": 5,
                                "open": 0,
                                "disabled": false,
                                "perms": null,
                                "type": 0,
                                "children": []
                            }
                        ]
                    },
                    {
                        "id": 295,
                        "parentId": 0,
                        "menuName": "其他管理",
                        "url": "",
                        "icon": "el-icon-s-marketing",
                        "orderNum": 5,
                        "open": 0,
                        "disabled": true,
                        "perms": "",
                        "type": 0,
                        "children": [
                            {
                                "id": 297,
                                "parentId": 295,
                                "menuName": "监控管理",
                                "url": "",
                                "icon": "el-icon-warning",
                                "orderNum": 1,
                                "open": 0,
                                "disabled": false,
                                "perms": "",
                                "type": 0,
                                "children": [
                                    {
                                        "id": 298,
                                        "parentId": 297,
                                        "menuName": "SQL监控",
                                        "url": "/druid",
                                        "icon": "el-icon-view",
                                        "orderNum": 1,
                                        "open": 0,
                                        "disabled": false,
                                        "perms": null,
                                        "type": 0,
                                        "children": []
                                    }
                                ]
                            },
                            {
                                "id": 341,
                                "parentId": 295,
                                "menuName": "个人博客",
                                "url": "/blog",
                                "icon": "el-icon-view",
                                "orderNum": 1,
                                "open": 0,
                                "disabled": false,
                                "perms": "",
                                "type": 0,
                                "children": []
                            },
                            {
                                "id": 296,
                                "parentId": 295,
                                "menuName": "swagger文档",
                                "url": "/swagger",
                                "icon": "el-icon-document",
                                "orderNum": 2,
                                "open": 0,
                                "disabled": false,
                                "perms": null,
                                "type": 0,
                                "children": []
                            },
                            {
                                "id": 318,
                                "parentId": 295,
                                "menuName": "图标管理",
                                "url": "/icons",
                                "icon": "el-icon-star-off",
                                "orderNum": 2,
                                "open": 1,
                                "disabled": false,
                                "perms": "",
                                "type": 0,
                                "children": []
                            }
                        ]
                    },
                    {
                        "id": 5,
                        "parentId": 0,
                        "menuName": "日志管理",
                        "url": "/logs",
                        "icon": "el-icon-camera",
                        "orderNum": 6,
                        "open": 0,
                        "disabled": false,
                        "perms": null,
                        "type": 0,
                        "children": [
                            {
                                "id": 271,
                                "parentId": 5,
                                "menuName": "登入日志",
                                "url": "/loginLog",
                                "icon": "el-icon-date",
                                "orderNum": 1,
                                "open": 0,
                                "disabled": false,
                                "perms": "login:log",
                                "type": 0,
                                "children": []
                            },
                            {
                                "id": 307,
                                "parentId": 5,
                                "menuName": "操作日志",
                                "url": "/logs",
                                "icon": "el-icon-edit",
                                "orderNum": 1,
                                "open": 1,
                                "disabled": false,
                                "perms": "",
                                "type": 0,
                                "children": []
                            }
                        ]
                    }
                ],
                userInfo: {},

            };
        },
        components: {
            MenuTree
        },
        methods: {
            /**
             *
             * 退出登入
             */
            async logout() {
                var res = await this.$confirm("此操作将退出系统, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消退出登入"
                    });
                });
                if (res == "confirm") {
                    window.localStorage.clear();
                    this.$router.push("/login");
                }
            },
            /**
             * 去系统首页
             */
            toWelcome(){
                this.$router.push("/Welcome");
            },
            /**
             加载菜单数据
             */
            // async getMenuList() {
            //     const { data: res } = await this.$http.get("user/findMenu");
            //     if (res.code !== 200)
            //         return this.$message.error("获取菜单失败:" + res.msg);
            //     this.menuList = res.data;
            // },
            /**
             获取用户信息
             */
            async getUserInfo() {
                const { data: res } = await this.$http.get("user/info");
                if (res.code !== 200) {
                    return this.$message.error("获取用户信息失败:" + res.msg);
                } else {
                    this.userInfo = res.data;
                    //保存用户
                    this.$store.commit("setUserInfo", res.data);
                }
            },
            /**
             * 菜单伸缩
             */
            toggleMenu() {
                this.isOpen = !this.isOpen;
            },

            /**
             * 点击交流
             */
            getContact(){
                const w = window.open('about:blank');
                w.location.href = '';
            }

        },
        mounted() {
            this.getUserInfo();
        },
        created() {
            // this.getMenuList();
            this.activePath = window.sessionStorage.getItem("activePath");
            // if(window.sessionStorage.getItem("activePath")==null){
            //   this.activePath='/welcome';
            // }
            setTimeout(() => {
                this.loading = false;
            }, 500);
        }
    };
</script>

<style>
    /* 为对应的路由跳转时设置动画效果 */

    .el-header {
        background-color: #001529;
        display: flex;
        justify-content: space-between;
        align-items: center;
        color: #fff;
        font-size: 19px;

        padding-left: 0px;
    }
    .el-aside {
        background-color:#001529
    }
    .el-main {
        background-color: #eaedf1;
    }
    .home-container {
        width: 100%;
        height: 100% !important;
    }
    .toggle-btn {
        background-color: #2d8cf0 !important;
        font-size: 10px;
        line-height: 24px;
        color: #fff;
        text-align: center;
        letter-spacing: 0.2em;
        cursor: pointer;
    }

</style>
